package com.example.text0926;

import android.content.Context;
import android.os.Bundle;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;

public class MainActivity extends AppCompatActivity {
    RecyclerView recyclerView;
    Context context;
    adapter adapter;

    List<Map<String,Object>> list1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        context = this;
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;

        });
        context = this;
        recyclerView=findViewById(R.id.recyclerView);

//手机示例
        int[] phonename = {R.drawable.p1, R.drawable.p2, R.drawable.p3};
        String[] price={"1999","2999","3999"};
        String[] config={"a","b","c"};

//// 联系人示例
//        int[] phonename = {R.drawable.contact, R.drawable.contact, R.drawable.contact};
//        String[] price={"爸爸","妈妈","姐姐"};
//        String[] config={"139 2341 5562","123 4567 8910","146 6281 7451"};

//接口不能new一个对象List，所以使用类ArrayList来new
        list1=new ArrayList<Map<String, Object>>() {};
        for(int i =0;i<phonename.length;i++)
        {//Hash Map根据类型（phonename、price、config）分堆
            Map<String,Object> map = new HashMap<>();
            map.put("name",phonename[i]);
            map.put("price",price[i]);
            map.put("config",config[i]);

            list1.add(map);
        }

        adapter= new adapter(context,list1);
        recyclerView.setAdapter(adapter);

        LinearLayoutManager manager=new LinearLayoutManager(context);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(manager);
    }
}